<template>
    <div id="page">
        <v-swiper></v-swiper>
        <v-Recommend></v-Recommend>
        <button @click='getAdv()'>点击获取广告信息</button>
    </div>
</template>

<script>
import Swiper from '@/components/son/swiper'
import vRecommend from '@/components/son/recommend'
import axios from 'axios'
export default {
  components: {
    vSwiper: Swiper,
    vRecommend
  },
  created() {
    //使用promise去解决异步函数同步调取 但是还是不优雅
      // this.$fetch.myGet('/findOne',{productId: '1ef360b8_1612741f18f_2'}).then(product=>{
      //     console.log(product)
      //     return this.$fetch.myGet('/adv')
      // }).then(adv=>{
      //   console.log(adv)
      // })
    //   axios.all([this.$fetch.myGet('/findOne',{productId: '1ef360b8_1612741f18f_2'}),this.$fetch.myGet('/adv')]).
    //   then(axios.spread(function(data1,data2){
    //       console.log(data1,data2)
    //   })).catch(error=>{
    //       console.log(error)
    //   })
    // var _this = this;
    // const tongbu = async () => {
    //   try {
    //     await setTimeout(function() {
    //       _this.$fetch
    //         .myGet('/findOne', { productId: '1ef360b8_1612741f18f_2' })
    //         .then(res => {
    //           console.log(res)
    //         })
    //     }, 3000)
    //     await this.$fetch.myGet('/adv').then(res => {
    //       console.log('我是广告')
    //       console.log(res)
    //     })
    //   } catch (error) {
    //     console.log(error)
    //   }
    // }
    // tongbu()
  },
  methods:{
   async getAdv(){
      this.$fetch({
        url:'/findOne',
        method:'GET',
        params:{
          productId:'1ef360b8_1612741f18f_2'
        }
      }).then(res=>{
        console.log(res.data)
      })
    }
  }
}
</script>

